<?php

namespace Morrow;

class PageController extends DefaultController {
	public function run() {

        $uid=$this->session->get("uid");
        $wid=$this->input->get('wid');

		if(!$uid){
			$this -> url -> redirect('home');
		}

        if(!$wid){
            $this -> url -> redirect('home');
        }
        
        else{

        	$this->load('Db', $this->config->get('db'));

        	$sql = $this->db->result('
				SELECT uid
				FROM webapps
				WHERE wid = ?', $wid);

        	if($sql['RESULT'][0]['uid']!== $uid){

				$this->session->set('messenger', 'changelinknotyours');
				$this -> url -> redirect('edit');
			}

			else{
				//delete webapp
				$this->db->delete('webapps', 'where wid = ?', true, $wid);
				$this->session->set('messenger', 'delete1');
				$this -> url -> redirect('edit');
			}

        }


	}
}